import 'package:cook_dinner/config/include.dart';
import 'package:cook_dinner/pages/login/login_page.dart';
import 'package:cook_dinner/pages/login/register.dart';
import 'package:cook_dinner/pages/login/view/login_view.dart';
import 'package:cook_dinner/widgets/login_nav.dart';
import 'package:flutter/material.dart';

class LoginPage extends StatefulWidget {
  const LoginPage({Key? key}) : super(key: key);

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> with TickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    _tabController = TabController(length: 2, vsync: this)
      ..addListener(() {
        print('${_tabController.index}');
        setState(() {});
      });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        resizeToAvoidBottomInset: true,
        backgroundColor: const Color(0xfffefefe),
        body: GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: () {
            FocusScope.of(context).unfocus();
          },
          child: SizedBox(
            width: double.infinity,
            height: double.infinity,
            child: Stack(
              children: [
                Positioned(
                  child: Image.asset(
                    'assets/images/login.jpg',
                    width: HYSizeFit.screenWidth,
                  ),
                ),
                SingleChildScrollView(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      LoginView.loginTitle(),
                      LoginView.loginBox(
                        child: Container(
                          width: double.infinity,
                          decoration: BoxDecoration(
                            color: const Color(0xffc2c2c2).withOpacity(0.15),
                            borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(20.rpx),
                              topRight: Radius.circular(20.rpx),
                            ),
                          ),
                          child: Stack(
                            children: [
                              Positioned(
                                child: LoginNav(
                                  cur: _tabController.index,
                                  child: Container(
                                    width: double.infinity,
                                    height: 80.rpx,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                              SizedBox(
                                width: double.infinity,
                                height: 80.rpx,
                                child: TabBar(
                                  controller: _tabController,
                                  tabs: const [
                                    Tab(text: '账号登录'),
                                    Tab(text: '一键注册'),
                                  ],
                                  isScrollable: true,
                                  padding: EdgeInsets.only(
                                      left: 0,
                                      right: 0,
                                      bottom: 20.rpx,
                                      top: 5.rpx),
                                  labelPadding:
                                      EdgeInsets.symmetric(horizontal: 50.rpx),
                                  indicatorPadding: EdgeInsets.all(0.rpx),
                                  labelColor: const Color(0xffFCC302),
                                  labelStyle: TextStyle(fontSize: 24.rpx),
                                  unselectedLabelColor: const Color(0xffA6A7A2),
                                  unselectedLabelStyle:
                                      TextStyle(fontSize: 24.rpx),
                                  indicatorSize: TabBarIndicatorSize.label,
                                  indicatorColor: const Color(0xffFCC302),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                      SizedBox(
                        width: double.infinity,
                        height: HYSizeFit.screenHeight - 320.rpx,
                        child: TabBarView(
                          controller: _tabController,
                          children: const [
                            LoginPageInt(),
                            RegisterPage(),
                          ],
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
